package com.lbs.dao.Impl;

import com.lbs.dao.CourseDao;
import com.lbs.entity.Course;
import com.lbs.utils.BaseDao;

import java.util.List;

/**
 * @author Administrator
 * @date 2021/6/1 11:54
 * @description
 **/
public class CourseDaoImpl extends BaseDao<Course> implements CourseDao {

    /**
     * 添加课程信息
     *
     * @param course
     * @return
     */
    @Override
    public int insertCourse(Course course) {
        String sql = "insert into course values(null,?,?,?,?,?,?,?,now())";
        Object[] params = {course.getCourseName(), course.getDescs(), course.getCourseType(),
                course.getCourseImage(), course.getCourseVideo(), course.getCoursePrice(), course.getStatus()};
        return update(sql, params);
    }

    /**
     * 模糊查询课程名称（且分页显示）
     *
     * @param sql
     * @param params
     * @return
     */
    @Override
    public List<Course> findCourseByName(String sql, Object... params) {
        return findMore(sql, Course.class, params);
    }

    /**
     * 修改课程信息
     * @param course
     * @return
     */
    @Override
    public int updateCourseById(Course course) {
        String sql = "update course set courseName = ?,descs = ?,courseType = ?,courseImage = ?," +
                "courseVideo = ?,coursePrice = ?,status = ?,createTime = now() where cid = ?";

        Object[] params = {course.getCourseName(), course.getDescs(), course.getCourseType(), course.getCourseImage(),
                course.getCourseVideo(), course.getCoursePrice(), course.getStatus(), course.getCid()};

        return update(sql, params);
    }

    /**
     * 批量删除
     * @param cid
     * @return
     */
    @Override
    public int deleteCourseById(String cid) {
        String sql = "delete from course where cid = ?";
        return update(sql,cid);
    }

    /**
     * 根据cid查询课程信息
     * @param cid
     * @return
     */
    @Override
    public Course findCourseById(int cid) {
        String sql = "select * from course where cid = ?";
        return findOne(sql,Course.class,cid);
    }

    /**
     * 查询所有的课程信息
     * @return
     */
    @Override
    public List<Course> selectAll() {
        String sql = "select * from course";
        return findMore(sql,Course.class,null);
    }
}
